package com.gxitsky.current;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * @author gxing
 * @desc TODO
 * @date 2022/5/22
 */
@Slf4j
public class MainTest2 {

    // 建立一个线程池，注意要放在外面，不要每次执行代码就建立一个，具体线程池的使用就不展开了
    public static ExecutorService commonThreadPool = new ThreadPoolExecutor(5, 5, 300L,
            TimeUnit.SECONDS, new LinkedBlockingQueue<>(10), new ThreadPoolExecutor.DiscardPolicy());

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        // 开始多线程调用
        List<Future<Month>> futures = new ArrayList<>();
        for (int i = 0; i < 12; i++) {
            int finalI = i;
            Future<Month> future = commonThreadPool.submit(() -> statOneMonthData(finalI));
            futures.add(future);
        }
        // 获取结果
        List<Month> list = new ArrayList<>();
        try {
            for (int i = 0; i < futures.size(); i++) {
                list.add(futures.get(i).get());
            }
        } catch (Exception e) {
            log.error("出现错误：", e);
        }
    }
    public static Month statOneMonthData(int month){
        return new Month();
    }
}
